def extract_values_keep_tuples1(nested_dict):
    values = []

    def _extract(item):
        if isinstance(item, dict):
            for v in item.values():
                _extract(v)
        elif isinstance(item, (list, tuple)):
            values.append(item)

    _extract(nested_dict)
    return values


from collections import deque

def extract_values_keep_tuples2(nested_dict):
    values = []
    queue = deque([nested_dict])
    
    while queue:
        current = queue.popleft()  # 使用队列而不是栈
        
        if isinstance(current, dict):
            # 按原始顺序处理值
            for value in current.values():
                queue.append(value)
        elif isinstance(current, (list, tuple)):
            values.append(current)
    
    return values


def extract_values_keep_tuples3(nested_dict):
    values = []
    stack = [nested_dict]
    
    while stack:
        current = stack.pop()
        if isinstance(current, dict):
            stack.extend(current.values())
        elif isinstance(current, (list, tuple)):
            values.append(current)
    
    return values


def db_bincode_to_model(db_bincode_source):
    db_data = copy.deepcopy(db_bincode_source)

    def convert_item(item_data):
        if not isinstance(item_data, dict):
            return item_data

        converted = {}

        for key, value in item_data.items():
            split_keys = list(key.split('_'))
            if len(split_keys) == 2:
                if split_keys[0] in converted:
                    converted[split_keys[0]].update({split_keys[1]: value})
                else:
                    converted[split_keys[0]] = {split_keys[1]: value}
            else:
                converted[key] = value
        return converted

    # def recursive_convert(data):
    #     priority_key = '_'.join([BincodeFileConstants.PRIORITY, BincodeFileConstants.PRIORITY])
    #     if isinstance(data, dict):
    #         result = {}
    #         for key, value in data.items():
    #             if isinstance(value, dict):
    #                 if isinstance(value, dict) and priority_key in value:
    #                     result[key] = convert_item(value)
    #                 else:
    #                     result[key] = recursive_convert(value)
    #             else:
    #                 result[key] = value
    #         return result
    #     else:
    #         return data
    #
    # return recursive_convert(db_data)

    # stack = [db_data]
    # priority_key = '_'.join([BincodeFileConstants.PRIORITY, BincodeFileConstants.PRIORITY])
    # while stack:
    #     current = stack.pop()
    #     if not isinstance(current, dict):
    #         continue
    #     for key, value in list(current.items()):
    #         if isinstance(value, dict):
    #             if priority_key in value:
    #                 current[key] = convert_item(value)
    #             else:
    #                 stack.append(value)
    # return db_data

    queue = deque([db_data])
    priority_key = 'priority_priority'
    while queue:
        current = queue.popleft()
        if not isinstance(current, dict):
            continue
        for key, value in list(current.items()):
            if isinstance(value, dict):
                if priority_key in value:
                    current[key] = convert_item(value)
                else:
                    queue.append(value)
    return db_data